131C - The World is a Theatre - CodeForces Solution


combinatorics math *1400

Please click on ads to support us..

Python Code:

def recur_factorial(n, end):
    if n < 1 or end >= n:
       return 1
    else:
       return n*recur_factorial(n-1, end)

n, m, t = list(map(int, input().split()))
x = 0
for i in range(4, t):
    comb1 = recur_factorial(n, n - i) / recur_factorial(i, 1)
    comb2 = recur_factorial(m, m - (t - i)) / recur_factorial(t - i, 1)
    x += (int(comb1) * int(comb2))
print(x)

C++ Code:

#include<bits/stdc++.h>
using namespace std;

long long ans;
int n,m,t;
long long C(int n,int k){
	long long f=1;
	for(int i=0;i<k;i++)f*=n-i,f/=i+1;
	return f;
}
main(){
	cin>>n>>m>>t;
	for(int i=4;i<=n&&i<t;i++){
		ans+=C(n,i)*C(m,t-i);
	}
	cout<<ans;
}

   		  						 				   				 	 	


Comments

Submit
0 Comments
More Questions

1163A - Eating Soup
787A - The Monster
807A - Is it rated
1096A - Find Divisible
1430C - Numbers on Whiteboard
1697B - Promo
208D - Prizes Prizes more Prizes
659A - Round House
1492C - Maximum width
171B - Star
1512B - Almost Rectangle
831B - Keyboard Layouts
814A - An abandoned sentiment from past
268C - Beautiful Sets of Points
1391C - Cyclic Permutations
11A - Increasing Sequence
1406A - Subset Mex
1365F - Swaps Again
50B - Choosing Symbol Pairs
1719A - Chip Game
454B - Little Pony and Sort by Shift
1152A - Neko Finds Grapes
1719B - Mathematical Circus
1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation
1719E - Fibonacci Strings
1696C - Fishingprince Plays With Array
1085A - Right-Left Cipher
1508B - Almost Sorted